import {makeObservable, observable, action, computed, runInAction} from 'mobx'

import {fetchSearchMusic} from '@/api/music'

export default class searchMusic {
  constructor() {
    makeObservable(this, {
      musicList: observable,
      getMusicList: action,
      musicNum: computed,
    })
  }
  musicList = []
  get musicNum () {
    return (this.musicList && this.musicList.length)
  }
  getMusicList = params => {
    fetchSearchMusic(params).then(res => {
      runInAction(() => {this.musicList = (res.song && res.song.list)})
    })
  }
}